package com.java.comprehensive.arithmetic.leecode.easy;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: comprehensive-service
 *
 * @description: 提莫攻击
 *
 * @author: 窦绍飞
 *
 * @create: 2021-12-27 15:38
 **/
public class LeetCode_495 {
	public static int findPoisonedDuration(int[] timeSeries, int duration) {

		// List<Integer> list = new ArrayList<>();
		Map<Integer, Integer> map = new HashMap<>(16);
		for (int i = 0; i < timeSeries.length; i++) {
			int num = timeSeries[i];
			for (int j = 0; j < duration; j++) {
				if (!map.containsKey(num + j)) {
					map.put(num + j, 0);
				}
			}
		}

		return map.size();
	}

	public static int findPoisonedDurationTwo(int[] timeSeries, int duration) {

		if (timeSeries.length == 0)
			return 0;// 没有中毒
		int sum = duration;// 最后一次攻击
		for (int i = 1; i < timeSeries.length; i++) {
			if (timeSeries[i] - timeSeries[i - 1] > duration) {// 攻击间隔大于中毒期
				sum += duration;
			} else
				sum += timeSeries[i] - timeSeries[i - 1];// 攻击间隔小于中毒期
		}
		return sum;

	}

	public static void main(String[] args) {
		int[] timeSeries = { 1, 2 };
		int duration = 2;
		int poisonedDuration = findPoisonedDuration(timeSeries, duration);
		System.out.println(poisonedDuration);

	}

}
